package com.mowh.multithreading.active.object.active;

import com.mowh.multithreading.active.object.active.active.object.ActiveObject;
import com.mowh.multithreading.active.object.active.active.object.Result;

/**
 * @author mowh1gd
 * @create 2023/11/28 15:58
 */
public class MakerClientThread extends Thread {
    private final ActiveObject activeObject;
    private final char fillChar;

    public MakerClientThread(String name, ActiveObject activeObject) {
        super(name);
        this.activeObject = activeObject;
        this.fillChar = name.charAt(0);
    }

    @Override
    public void run() {
        try {
            for (int i = 0; true; i++) {
                Result<String> result = activeObject.makeString(i, fillChar);//代理返回一个FutureResult
                Thread.sleep(10);//等待真实值生成
                String value = result.getResultValue();//获取FutureResult的真实值（真实值RealResult已生成则返回真实值，否则为空
                System.out.println(Thread.currentThread().getName() + ": value = " + value);
            }
        } catch (InterruptedException e) {
        }
    }
}
